<?php
/*
 * @Author: 天羽落星辰
 * @Date: 2020-07-17 15:04:53
 * @LastEditors: 天羽落星辰
 * @LastEditTime: 2020-08-23 14:45:27
 * @Description: file content
 */ 

namespace app\admin\controller;

use app\common\controller\Backend;
use think\Config;

/**
 * 控制台
 *
 * @icon fa fa-dashboard
 * @remark 用于展示当前系统中的统计数据、统计报表及重要实时数据
 */
class Dashboard extends Backend
{

    /**
     * 查看
     */
    public function index()
    {
        $seventtime = \fast\Date::unixtime('day', -7);
        $paylist = $createlist = [];
        for ($i = 0; $i < 7; $i++)
        {
            $day = date("Y-m-d", $seventtime + ($i * 86400));
            $createlist[$day] = mt_rand(20, 200);
            $paylist[$day] = mt_rand(1, mt_rand(1, $createlist[$day]));
        }

        $hooks = config('addons.hooks');
        $uploadmode = isset($hooks['upload_config_init']) && $hooks['upload_config_init'] ? implode(',', $hooks['upload_config_init']) : 'local';
        $addonComposerCfg = ROOT_PATH . '/vendor/karsonzhang/fastadmin-addons/composer.json';
        Config::parse($addonComposerCfg, "json", "composer");
        $config = Config::get("composer");
        $addonVersion = isset($config['version']) ? $config['version'] : __('Unknown');


        $totaluser = db('user')->count();
        $yesterday_user = db('user')->whereTime('jointime','yesterday')->count();
        $month_user = db('user')->whereTime('jointime','month')->count();
        $totalorderamount = db('order')->count();
        $order_users = db('user')->where('order_sum','>',0)->count();
        $users_stay_usdt = db('user')->sum('usdt');
        $users_usdt_under_review = db('qianbao_sysetm_log')->where('bizhong','usdt')->where('type',2)->where('zt','<>',1)->where('zt','<>',0)->sum('money');
        $users_usdt_adopt = db('qianbao_sysetm_log')->where('bizhong','usdt')->where('type',2)->where('zt',1)->sum('money');
        $yesterday_usdt = db('qianbao_sysetm_log')->where('bizhong','usdt')->where('type',1)->whereTime('createtime','yesterday')->sum('money');
        $month_usdt = db('qianbao_sysetm_log')->where('bizhong','usdt')->where('type',1)->whereTime('createtime','month')->sum('money');
        $total_usdt = db('qianbao_sysetm_log')->where('bizhong','usdt')->where('type',1)->sum('money');

        $orders = db('order')->where('zt',1)->select();
        $orders_stay_release_sum = 0;
        foreach($orders as $v){
            $days =  intval(($v['overtime'] - time()) / 86400);
            $profit = round($v['price'] * $v['shouyi'] / 100, 4);
            $orders_stay_release_sum += ($days * $profit);
        }
        // $totalorderamount = db('order')->count();
        
        $this->view->assign([
            'totaluser'                 => $totaluser,  // 总会员人数
            'totalorder'                => $totalorderamount, // 总订单数
            'yesterday_user'            => $yesterday_user, // 昨日新增人数
            'month_user'                => $month_user, // 本月新增人数
            'order_users'               => $order_users, // 有效会员数（正在合约中）
            'orders_stay_release_sum'   => $orders_stay_release_sum, // 合约剩余释放资产U
            'users_stay_usdt'           => round($users_stay_usdt,2), // 会员未提U
            'users_usdt_under_review'   => abs($users_usdt_under_review), // 会员提币审核中U
            'users_usdt_adopt'          => abs($users_usdt_adopt), // 会员提币审核通过U
            'yesterday_usdt'            => $yesterday_usdt, // 昨日新增U
            'month_usdt'                => $month_usdt, // 本月新增U
            'total_usdt'                => $total_usdt, // 总计U
        ]);

        return $this->view->fetch();
    }

}
